package com.markul.android.ui.mark.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.markul.android.R
import com.markul.android.ui.mark.OnItemClickListener

class MarkIconAdapter(val iconList:List<Int>):
    RecyclerView.Adapter<RecyclerView.ViewHolder>(){

    private var onIconClickListener: OnItemClickListener? = null

    inner class ViewHolder(itemView:View): RecyclerView.ViewHolder(itemView){
        val iconImage:ImageView=itemView.findViewById(R.id.markIcon)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        val view=LayoutInflater.from(parent.context)
            .inflate(R.layout.item_mark_icon,parent,false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        val icon=iconList[position]
        Glide.with(holder.itemView.context).load(icon)
            .into((holder as ViewHolder).iconImage)
        holder.iconImage.setOnClickListener {
            onIconClickListener?.onIconClick(position)
        }

    }

    override fun getItemCount()=iconList.size

    fun setOnMyClickListener(onClickListener: OnItemClickListener?
    ) {
        onIconClickListener = onClickListener
    }

}